package cn.jaye.fabric.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.jaye.fabric.application.ServiceApplicationService;
import cn.jaye.fabric.common.constant.Global;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jaye
 * @create 2017-12-29 14:24
 */
@RestController
@RequestMapping("/service")
public class ServiceController {

    @Autowired
    private ServiceApplicationService serviceApplicationService;

    @PostMapping("/list")
    public String list() {
        String data = serviceApplicationService.listService();
        JSONObject jsonObject = JSON.parseObject(data);
        if (Global.SUCCESS_FLAG.equals(jsonObject.getInteger("code"))) {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            return JSON.toJSONString(jsonArray);
        }
        return null;
    }
}
